package gruppe7.tlrs;
import java.util.HashMap;
import java.util.Set;

public class StationList {
	private HashMap<String, Station> stations;
	public StationList(){
		stations = new HashMap<String, Station>();
	}
	public Station getStation(String stationName){
		return stations.get(stationName);
	}
	public Boolean createStation(String stationName, Integer zone){
		Boolean result=false;
		if (stations.containsKey(stationName))
			result = false;	
		else {
			stations.put(stationName, new Station(stationName,zone));
			result = true;
		}
		return result;
	}
	public String showAll(){
		Set <String> keys = stations.keySet();
		String result ="";
		for(String key : keys){
			result = result + "\n" + (stations.get(key).toString());
		}
		return result;
	}
	
	public HashMap<String, Station> getStations()
	{
		return stations;
	}
	
	public boolean updateStation(String oldName, String stationName, Integer zone, String manager, String date, String comment)
	{
		Station station = new Station(stationName, zone);
		station.setComment(comment);
		station.setManager(manager);
		station.setErectionDate(date);
		boolean result = false;
		
		if(stations.containsKey(stationName))
		{
			
			stations.put(stationName, station);
			result = true;
		}
		else if (stations.containsKey(oldName))
		{
			stations.put(stationName, station);
			stations.remove(oldName);
			result=true;
		}
		return result;
	}
}
